package se.gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;
import java.awt.Rectangle;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;

public class PanelCorrerServidor extends JPanel
{

    private static final long serialVersionUID = 1L;
    private JButton btnCorrer = null;
    private JLabel lblPuerto = null;
    private JTextField txtPuerto = null;
    private JLabel lblError = null;
    private JButton btnParar = null;
    private InterfazServidor ventanaPrincipal;

    /**
     * This is the default constructor
     */
    public PanelCorrerServidor( InterfazServidor ventanaPrincipal )
    {
        super( );
        this.ventanaPrincipal = ventanaPrincipal;
        initialize( );
    }

    /**
     * This method initializes this
     * 
     * @return void
     */
    private void initialize( )
    {
        lblError = new JLabel( );
        lblError.setBounds( new Rectangle( 278, 16, 51, 31 ) );
        lblError.setForeground( Color.red );
        lblError.setFont( new Font( "Lucida Grande", Font.BOLD, 30 ) );
        lblError.setText( "X" );
        lblError.setVisible( false );
        lblPuerto = new JLabel( );
        lblPuerto.setBounds( new Rectangle( 30, 22, 130, 23 ) );
        lblPuerto.setText( "Puerto de escucha:" );
        this.setSize( 588, 55 );
        this.setLayout( null );
        this.setBorder( BorderFactory.createTitledBorder( null, "Correr Servidor", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null ) );
        this.setPreferredSize( new Dimension( 588, 55 ) );
        this.add( getBtnCorrer( ), null );
        this.add( lblPuerto, null );
        this.add( getTxtPuerto( ), null );
        this.add( lblError, null );
        this.add( getBtnParar( ), null );
    }

    /**
     * This method initializes btnCorrer
     * 
     * @return javax.swing.JButton
     */
    private JButton getBtnCorrer( )
    {
        if( btnCorrer == null )
        {
            btnCorrer = new JButton( );
            btnCorrer.setText( "Correr Servidor" );
            btnCorrer.setLocation( new Point( 336, 13 ) );
            btnCorrer.setSize( new Dimension( 116, 36 ) );
            btnCorrer.addActionListener( new java.awt.event.ActionListener( )
            {
                public void actionPerformed( java.awt.event.ActionEvent e )
                {
                    ventanaPrincipal.correrServidor( Integer.valueOf( txtPuerto.getText( ) ) );
                }
            } );
        }
        return btnCorrer;
    }

    /**
     * This method initializes txtPuerto
     * 
     * @return javax.swing.JTextField
     */
    private JTextField getTxtPuerto( )
    {
        if( txtPuerto == null )
        {
            txtPuerto = new JTextField( );
            txtPuerto.setText( "9876" );
            txtPuerto.setBounds( new Rectangle( 175, 19, 96, 28 ) );
        }
        return txtPuerto;
    }

    /**
     * This method initializes btnParar
     * 
     * @return javax.swing.JButton
     */
    private JButton getBtnParar( )
    {
        if( btnParar == null )
        {
            btnParar = new JButton( );
            btnParar.setText( "Parar Servidor" );
            btnParar.setSize( new Dimension( 116, 36 ) );
            btnParar.setLocation( new Point( 458, 13 ) );
            btnParar.addActionListener( new java.awt.event.ActionListener( )
            {
                public void actionPerformed( java.awt.event.ActionEvent e )
                {
                    ventanaPrincipal.pararServidor( );
                }
            } );
        }
        return btnParar;
    }

} // @jve:decl-index=0:visual-constraint="10,10"
